# -*- coding: utf-8 -*-

from django.contrib.syndication.views import Feed

from mdcssport.mdcsapp.models import News, Match

class LatestNews(Feed):
    title = "Najnovije vesti"
    link = "/news/"
    description = "Najnovije vesti sa sport.mdcs.rs"
    title_template = 'feeds/latest_news_title.html'
    description_template = 'feeds/latest_news_description.html'
    
    def items(self):
        return News.objects.order_by('-date_updated')[:20]

    def item_link(self, item):
        return '/mdcs/news/%d/' % item.id

class LatestMatches(Feed):
    title = "Najnoviji mečevi"
    link = "/matches/"
    description = "Najnovije odigrani mečevi na sport.mdcs.rs"
    title_template = 'feeds/latest_matches_title.html'
    description_template = 'feeds/latest_matches_description.html'
    
    def items(self):
        return Match.objects.filter(winner__isnull=False).order_by('-date_played')[:50]

    def item_link(self, item):
        return '/mdcs/'